package com.itfreer.data.metadata.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.itfreer.form.api.entity.EntityBase;

/**
 * 定义字典标准字典项实体类
 */
@Entity(name = "data_dictionary")
@Table(indexes = { @Index(name = "f_d_dicname", columnList = "s_dicname") })
public class DataDictionaryEntity extends EntityBase implements Serializable {

	private static final long serialVersionUID = 6625281869957696137L;

	/**
	 * 唯一值
	 */
	@Id
	@Column(name = "guid", length = 50, nullable = false)
	private String guid;

	/**
	 * 字典名称
	 */
	@Column(name = "s_dicname", nullable = true)
	private String dicName;

	/**
	 * id值，系统应用中必需关联此值
	 */
	@Column(name = "id", length = 50, nullable = false)
	private String id;

	/**
	 * 代码值
	 */
	@Column(name = "s_code", nullable = true)
	private String code;

	/**
	 * 显示名称
	 */
	@Column(name = "s_display", nullable = true)
	private String display;

	/**
	 * 拼音简称
	 */
	@Column(name = "s_abbreviation", nullable = true)
	private String abbreviation;

	/**
	 * 单位
	 */
	@Column(name = "s_units", nullable = true)
	private String units;

	/**
	 * 排序值
	 */
	@Column(name = "i_order", nullable = true)
	private Integer order;

	/**
	 * 是否有效
	 */
	@Column(name = "b_valid", nullable = true)
	private Boolean valid = true;

	/**
	 * 备注
	 */
	@Column(name = "s_info", nullable = true)
	private String info;

	/**
	 * 上级ID值
	 */
	@Column(name = "s_pid", nullable = true)
	private String pid;

	/**
	 * 级别
	 */
	@Column(name = "i_level", nullable = true)
	private Integer level;

	/**
	 * 是否为最后级别
	 */
	@Column(name = "b_leaf", nullable = true)
	private Boolean leaf;

	/**
	 * 当前级别的其它属性
	 */
	@Transient
	private Map<String, Object> other = new HashMap<String, Object>();

	/**
	 * 租户ID
	 */
	@Column(name = "s_tenantID", length = 50, nullable = true)
	private String tenantID;

	/**
	 * 租户名称
	 */
	@Column(name = "s_tenantName", length = 50, nullable = true)
	private String tenantName;
	
	/**
	 * 共享租户ID
	 */
	@Column(name = "s_shareTenantID", nullable = true, columnDefinition = "text")
	private String shareTenantID;

	/**
	 * 子字典对象
	 */
	@Transient
	private List<DataDictionaryEntity> children = new ArrayList<DataDictionaryEntity>();

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public void setDicName(String dic) {
		this.dicName = dic;
	}

	/**
	 * id值，主键，唯一值 系统应用中必需关联此值
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * 代码值
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * 显示名称
	 */
	public void setDisplay(String display) {
		this.display = display;
	}

	/**
	 * 拼音简称
	 */
	public void setAbbreviation(String abbreviation) {
		this.abbreviation = abbreviation;
	}

	public void setUnits(String units) {
		this.units = units;
	}

	/**
	 * 排序值
	 */
	public void setOrder(Integer order) {
		this.order = order;
	}

	/**
	 * 是否有效
	 */
	public void setValid(Boolean isValid) {
		this.valid = isValid;
	}

	/**
	 * 备注
	 */
	public void setInfo(String info) {
		this.info = info;
	}

	/**
	 * 上级ID值
	 */
	public void setPid(String pid) {
		this.pid = pid;
	}

	/**
	 * 级别
	 */
	public void setLevel(Integer level) {
		this.level = level;
	}

	/**
	 * 是否为最后节点
	 */
	public void setLeaf(Boolean leaf) {
		this.leaf = leaf;
	}

	@Transient
	public Map<String, Object> getOther() {
		return other;
	}

	public void setOther(Map<String, Object> other) {
		this.other = other;
	}

	@Transient
	public List<DataDictionaryEntity> getChildren() {
		return children;
	}

	public void setChildren(List<DataDictionaryEntity> children) {
		this.children = children;
	}

	/**
	 * 租户ID
	 */
	public void setTenantID(String tenantID) {
		this.tenantID = tenantID;
	}

	/**
	 * 租户名称
	 */
	public void setTenantName(String tenantName) {
		this.tenantName = tenantName;
	}

	/**
	 * 唯一值
	 */
	public String getGuid() {
		return guid;
	}

	/**
	 * id值，系统应用中必需关联此值
	 */
	public String getId() {
		return id;
	}

	/**
	 * 外键，所属的字典
	 */
	public String getDicName() {
		return dicName;
	}

	/**
	 * 代码值
	 */
	public String getCode() {
		return code;
	}

	/**
	 * 显示名称
	 */
	public String getDisplay() {
		return display;
	}

	/**
	 * 拼音简称
	 */
	public String getAbbreviation() {
		return abbreviation;
	}

	/**
	 * 单位
	 */
	public String getUnits() {
		return units;
	}

	/**
	 * 排序值
	 */
	public Integer getOrder() {
		return order;
	}

	/**
	 * 是否有效
	 */
	public Boolean getValid() {
		return valid;
	}

	/**
	 * 备注
	 */
	public String getInfo() {
		return info;
	}

	/**
	 * 上级ID值
	 */
	public String getPid() {
		return pid;
	}

	/**
	 * 级别
	 */
	public Integer getLevel() {
		return level;
	}

	/**
	 * 是否为最后级别
	 */
	public Boolean getLeaf() {
		return leaf;
	}

	/**
	 * 租户ID
	 */
	public String getTenantID() {
		return tenantID;
	}

	/**
	 * 租户名称
	 */
	public String getTenantName() {
		return tenantName;
	}
	
	@Override
	public String getShareTenantID() {
		return shareTenantID;
	}

    @Override
	public void setShareTenantID(String shareTenantID) {
		this.shareTenantID = shareTenantID;
	}

	public DataDictionaryEntity copy() {
		DataDictionaryEntity item = new DataDictionaryEntity();
		item.setId(this.getId());
		item.setPid(this.getPid());
		item.setAbbreviation(this.getAbbreviation());
		item.setCode(this.getCode());
		item.setDisplay(this.getDisplay());
		item.setInfo(this.getInfo());
		item.setLeaf(this.getLeaf());
		item.setLevel(this.getLevel());
		item.setOrder(this.getOrder());
		item.setOther(this.getOther());
		item.setUnits(this.getUnits());
		item.setValid(this.getValid());
		item.setTenantID(this.getTenantID());
		item.setTenantName(this.getTenantName());
		item.setShareTenantID(this.getShareTenantID());
		return item;
	}
}
